<template>
  <el-dropdown trigger="click" class="international" @command="handleSetLanguage">
    <div>
      <svg-icon class-name="international-icon" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item in languages" :key="item.value" :command="item.value">
        {{ item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import { getDic } from '@/utils/auth'
export default {
  computed: {
    language() {
      return this.$store.getters.language
    }
  },
  created() {
    this.languages = getDic('language')
    const index = this.languages.findIndex(item => item.value === '')
    this.languages.splice(index, 1)
  },
  methods: {
    handleSetLanguage(lang) {
      // this.$i18n.locale = lang
      this.$store.dispatch('app/setLanguage', lang)
      location.reload()
    }
  }
}
</script>
